/**
 * 正则表达式
 */
const PATTERN = {
  USER_NAME: /^[A-Za-z\u4e00-\u9fa5 ]+$/,
  USER_ID_CARD: /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
  USER_PHONE: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
  CODE: /^\d{4}$/,
  APPOINTMENT_TIME: /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:00$/,
}

/**
 * 登录表单验证规则
 */
export const LOGIN_FORM_RULES = {
  name: [
    {
      required: true,
      message: "请输入姓名",
      trigger: ["blur"],
    },
    {
      min: 2,
      max: 20,
      message: "姓名长度应在2~20个字符之间",
      trigger: ["blur", "change"],
    },
    {
      pattern: PATTERN.USER_NAME,
      message: "姓名只能包含中文、英文和空格",
      trigger: ["blur", "change"],
    },
  ],
  phone: [
    {
      required: true,
      message: "请输入手机号",
      trigger: ["blur"],
    },
    {
      min: 11,
      max: 11,
      message: "手机号长度应为11位",
      trigger: ["blur", "change"],
    },
    {
      pattern: PATTERN.USER_PHONE,
      message: "请输入正确的手机号码",
      trigger: ["blur", "change"],
    },
  ],
  code: [
    {
      required: true,
      message: "请输入验证码",
      trigger: ["blur", "change"],
    },
    {
      pattern: PATTERN.CODE,
      message: "验证码应为4位数字",
      trigger: ["blur", "change"],
    },
  ],
};

/**
 * 预约表单验证规则
 */
export const APPOINTMENT_FORM_RULES = {
  userName: [
    { required: true, message: "请输入姓名", trigger: ["blur"] },
    {
      min: 2,
      max: 20,
      message: "姓名长度应在2~20个字符之间",
      trigger: ["blur", "change"],
    },
    {
      pattern: PATTERN.USER_NAME,
      message: "姓名只能包含中文、英文和空格",
      trigger: ["blur"],
    },
  ],
  userIdCard: [
    { required: true, message: "请输入身份证", trigger: ["blur"] },
    {
      min: 18,
      max: 18,
      message: "身份证长度应为18位",
      trigger: ["blur", "change"],
    },
    {
      pattern: PATTERN.USER_ID_CARD,
      message: "请输入正确的身份证号码",
      trigger: ["blur"],
    },
  ],
  userPhone: [
    {
      required: true,
      message: "请输入手机号",
      trigger: ["blur"],
    },
    {
      min: 11,
      max: 11,
      message: "手机号长度应为11位",
      trigger: ["blur", "change"],
    },
    {
      pattern: PATTERN.USER_PHONE,
      message: "请输入正确的手机号码",
      trigger: ["blur", "change"],
    },
  ],
  code: [
    { required: true, message: "请输入验证码", trigger: ["blur", "change"] },
    {
      pattern: PATTERN.CODE,
      message: "验证码应为4位数字",
      trigger: ["blur", "change"],
    },
  ],
  userCompany: [
    { required: true, message: "请输入所在单位", trigger: ["blur", "change"] },
    {
      min: 1,
      max: 50,
      message: "所在单位字数长度应在1~50个字符之间",
      trigger: ["blur", "change"],
    },
  ],
  professorName: [
    {
      required: true,
      message: "请输入预约专家姓名",
      trigger: ["blur", "change"],
    },
    {
      min: 1,
      max: 20,
      message: "专家姓名字数长度应在1~20个字符之间",
      trigger: ["blur", "change"],
    },
  ],
  appointmentTime: [
    { required: true, message: "请选择预约时间", trigger: ["blur", "change"] },
    {
      pattern: PATTERN.APPOINTMENT_TIME,
      message: "时间格式应为 yyyy-mm-dd hh:mm:00",
      trigger: ["blur", "change"],
    },
  ],
  appointmentContent: [
    { required: true, message: "请输入到访事项", trigger: ["blur", "change"] },
    {
      min: 1,
      max: 250,
      message: "到访事项字数长度应在1~250个字符之间",
      trigger: ["blur", "change"],
    },
  ],
};

/**
 * 权限确认表单验证
 */
export const PERMISSION_FORM_RULES = {
  phone: [
    {
      required: true,
      message: "请输入手机号",
      trigger: ["blur"],
    },
    {
      min: 11,
      max: 11,
      message: "手机号长度应为11位",
      trigger: ["blur", "change"],
    },
    {
      pattern: PATTERN.USER_PHONE,
      message: "请输入正确的手机号码",
      trigger: ["blur", "change"],
    },
  ],
};

/**
 * 错误信息
 */
export const ERROR_MESSAGE = {
  UNAUTHORIZED: "你好像没有登录哦",
  FORBIDDEN: "你好像没有权限哦",
  NETWORK_ERROR: "服务器貌似开小差了，请稍后再试试吧",
};

/**
 * 事件监听
 */
export const EVENT_KEYS = {
  UNAUTHORIZED: "unauthorized",
  FORBIDDEN: "forbidden",
  NETWORK_ERROR: "networkError",
};

/**
 * 错误类型
 */
export const ERROR_TYPE = {
  NETWORK: 'network',
  BUSINESS: 'business',
  VALIDATE: 'validate',
};

/**
 * 时间格式
 */
export const TIME_FORMAT = {
  FORMAL: "yyyy-mm-dd hh:MM:ss",
  SHORT: "yyyy-mm-dd",
  TIME: "hh:MM:ss",
};
